<?php
require_once('php/lib/mvc/controller.php');

config('DefaultController', 'default_controller');

/**
 * Default controller.
 *
 * @author Pascal de Vink
 */
class DefaultController extends Controller {

	/**
	 * View action.
	 *
	 * @access public
	 */
	function view($page) {
	
		# check for redirect
		if ($page['redirect']) {
			$this->application->redirect('./?' . $page['redirect']);
		}
	
		# check if file exists
		$file_url = 'content/' . $page['file'];
		if (!file_exists($file_url)) die('Pagina bestaat niet');
		if (is_dir($file_url)) die('Pagina bestaat niet');
				
		# get content type
		$ext = file_extension($file_url);
		if ($ext == 'html') {
			$type = 'html';
		} else {
			$type = 'php';
		}

		# create view
		if ($type == 'html') {
			
			# html
			require_once('php/views/html_view.php');
			return new HtmlView($file_url);
		} else {
			
			# php
			require_once('php/views/php_view.php');
			return new PhpView($file_url);
		}
	}
}

?>